package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Home.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	//import mx.containers.Panel;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.plaf.*;
	import org.aswing.skinbuilder.SkinProgressBarBackground;
	import org.aswing.skinbuilder.SkinProgressBarForeground;
	
	public class PanelMainAcceptableTaskItem extends JPanel
	{
		//members define
		//members define
		private var panelType:JPanel;
		private var textName:JTextArea;
		public function PanelMainAcceptableTaskItem()
		{
			//component creation
			setSize(new IntDimension(190, 100));
			setPreferredSize(new IntDimension(190, 100));
			var layout0:EmptyLayout = new EmptyLayout();
			setLayout(layout0);
			
			panelType = new JPanel();
			panelType.setLocation(new IntPoint(0, 0));
			panelType.setSize(new IntDimension(20, 20));
			panelType.setPreferredSize(new IntDimension(20, 20));
			
			textName = new JTextArea();
			textName.setLocation(new IntPoint(20, 0));
			textName.setSize(new IntDimension(170, 20));
			textName.setPreferredSize(new IntDimension(170, 20));
			
			//component layoution
			append(panelType);
			append(textName);

			textName.addEventListener(MouseEvent.CLICK,onClickName);
			
			var filter:GlowFilter;
			filter = new GlowFilter(0x000000, 1, 2, 2, 100);
			textName.filters = (new Array(filter));
			
			textName.setBackgroundDecorator(null);
			textName.setEditable(false);
			textName.setForeground(ASColor.GREEN);
			textName.setBorder(new EmptyBorder);
			//textName.setBounds(new IntRectangle(0,0,0,0));
			textName.mouseEnabled = false;
			
		}
		private function onClickName(e:Event):void
		{
			if(_item.accepte_npc_id != 0)
			{
				PanelMainHelp.tmpMapId = int(_item.accepte_map_id);
				PanelMainHelp.tmpNpcId = int(_item.accepte_npc_id);
				var objMapCSV:Object = Client.getInstance().GetMapCSV(PanelMainHelp.tmpMapId);
				if(objMapCSV == null)
				{
					return;
				}
				if(PanelMainHelp.tmpMapId != CharInfo.mapId)
				{
					PanelMainHelp.tmpMapX = int(objMapCSV.base_x);
					PanelMainHelp.tmpMapY = int(objMapCSV.base_y);
					Client.getInstance().sendPacketLogic(9,[int(PanelMainHelp.tmpMapId),CharInfo.mapLineId,int(0),int(0),int(objMapCSV.base_x),int(objMapCSV.base_y)]);
				}
				else
				{
					var npc:ObjectCharNPC = SceneMain.getInstance().getObjectByNpcId(PanelMainHelp.tmpNpcId);
					if(npc != null)
					{
						if(Point.distance(npc.getPos(),CharInfo.objSelf.getPos()) > 100)
						{
							PanelMainHelp.tmpMapX = int(npc.getPos().x);
							PanelMainHelp.tmpMapY = int(npc.getPos().y);
							Client.getInstance().sendPacketLogic(9,[int(PanelMainHelp.tmpMapId),CharInfo.mapLineId,int(0),int(0),int(npc.getPos().x),int(npc.getPos().y)]);
							return;
						}
						
						FrameNPCDialog._currentCharNpc = npc;
						if(FrameNPCDialog._currentCharNpc != null)
						{
							Client.getInstance().sendPacketLogic(900,[int(PanelMainHelp.tmpNpcId)]);
							PanelMainHelp.tmpNpcId = -1;
							PanelMainHelp.tmpMapId = -1;
							PanelMainHelp.tmpMapX = 0;
							PanelMainHelp.tmpMapY = 0;
						}
					}
				}
			}
		}

		static public function formatTime(time:int):String
		{
			var str:String = new String;
			var hour:int = time / 3600;
			var min:int = (time % 3600)/60;
			var second:int = time%60;
			if(hour > 0)str += ((hour < 10) ? "0" : "") + hour+':';
			if(min >= 0)str += ((min < 10) ? "0" : "") + min+':';
			str += ((second < 10) ? "0" : "") + second;
			return str;
		}
		
		private var _item:Object = null;
		
		public function set item(val:Object):void
		{
			_item = val;
			
			if(_item == null)
			{
				return;
			}

			var text:String = '';
			var objCSVInfo:Object = _item;

			if(_item.require_level > CharInfo.m_nLevel)
				text += '<a href=\"event:0\"><font color="#FF0000">';
			else
				text += '<a href=\"event:0\"><font color="#00FF00">';
			text += '['+_item.require_level+']'
			text += _item.name+'</font>';
			text +='</a>';
			
			textName.setHtmlText(text);
			textName.pack();
			textName.paintImmediately();
			
			if(objCSVInfo.type == 0)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_0") as DisplayObject));
			if(objCSVInfo.type == 1)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_1") as DisplayObject));
			if(objCSVInfo.type == 2)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_2") as DisplayObject));
			if(objCSVInfo.type == 3)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_3") as DisplayObject));
			if(objCSVInfo.type == 4)panelType.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_task_type_4") as DisplayObject));

			setPreferredSize(new IntDimension(190, 20));
			pack();
			this.paintImmediately();
		}
		public function get item():Object
		{
			return _item;
		}
		
	}
}